package main

func reverseString(s string) string {
	// 将字符串转换为 rune 切片
	runes := []rune(s)
	// 获取 rune 切片的长度
	n := len(runes)
	// 反转 rune 切片
	for i := 0; i < n/2; i++ {
		runes[i], runes[n-1-i] = runes[n-1-i], runes[i]
	}
	// 将 rune 切片转换回字符串
	return string(runes)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func fun(s string, a rune, b rune) int {
	ans := 0
	freqA := 0
	freqB := 0
	hasB := false
	for _, ch := range s {
		if ch == a {
			freqA++
		} else if ch == b {
			freqB++
			hasB = true
		}
		if hasB {
			ans = max(ans, freqA-freqB)
		}
		if freqA < freqB {
			freqA = 0
			freqB = 0
			hasB = false
		}
	}
	return ans
}
func largestVariance(s string) int {
	ans := 0
	t := reverseString(s)
	for a := 'a'; a <= 'z'; a++ {
		for b := 'a'; b <= 'z'; b++ {
			if a == b {
				continue
			}
			ans = max(ans, fun(s, a, b))
			ans = max(ans, fun(t, a, b))
		}
	}
	return ans
}

func main() {

}
